import globals from 'globals'
import pluginJs from '@eslint/js'
import pluginVue from 'eslint-plugin-vue'
import vueParser from 'vue-eslint-parser'
import standard from 'eslint-config-standard'

// 新增插件导入
import pluginImport from 'eslint-plugin-import'
import pluginN from 'eslint-plugin-n'
import pluginPromise from 'eslint-plugin-promise'

export default [
  // 基础配置
  {
    files: ['**/*.{js,mjs,cjs}'],
    languageOptions: {
      globals: {
        process: 'readonly',
        ...globals.browser,
        ...globals.es2021
      },
      ecmaVersion: 2022,
      sourceType: 'module'
    }
  },

  // Vue文件解析配置
  {
    files: ['**/*.vue'],
    languageOptions: {
      parser: vueParser,
      parserOptions: {
        parser: {
          js: 'espree',
          ts: '@typescript-eslint/parser'
        }
      }
    }
  },

  // 核心插件配置
  pluginJs.configs.recommended,
  ...pluginVue.configs['flat/essential'],

  // 自定义规则
  {
    // 修改包含standard规则的配置块
    plugins: {
      import: pluginImport, // 添加import插件声明
      n: pluginN, // 新增n插件声明
      promise: pluginPromise // 新增promise插件声明
    },
    rules: {
      ...standard.rules,
      'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
      'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
      'vue/multi-word-component-names': 'off',
      'comma-dangle': ['error', 'never'],
      'object-curly-spacing': ['error', 'always']
    }
  }
]
